﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TFSCommon.Settings
{
    public class MySettingsManager : Common.SettingsManager
    {
        public const string ParameterTFSCollection = "TFS_COLLECTION";
        public const string ParameterTFSCollectionUri = "TFS_COLLECTION_URI";
        public const string ParameterTFSProject = "TFS_PROJECT";

        public MySettingsManager()
            : base()
        {
            Add(ParameterTFSCollection);
            Add(ParameterTFSCollectionUri);
            Add(ParameterTFSProject);
        }

        public MySettingsManager(String parameters)
            : this()
        {
            Set(parameters);
        }

        public String Collection
        {
            get { return this[ParameterTFSCollection]; }
            set { this[ParameterTFSCollection] = value; }
        }

        public String CollectionUri
        {
            get { return this[ParameterTFSCollectionUri]; }
            set { this[ParameterTFSCollectionUri] = value; }
        }

        public String Project
        {
            get { return this[ParameterTFSProject]; }
            set { this[ParameterTFSProject] = value; }
        }

        public override bool ValidateParameter(Common.Controls.SettingsControl sc)
        {
            Validating v = new Validating(this.ToString(), sc);
            v.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            //v.Location = 

            Point position = new Point(0,0);
            Size width = new Size(0,0);

            Control c = sc;

            while (c != null)
            {
                if (c is Form)
                {
                    int left_space = (c.Width - (c as Form).ClientSize.Width) / 2;
                    int top_space = (c.Height - (c as Form).ClientSize.Height) - left_space;
                    position = new Point(position.X + left_space, position.Y + top_space);
                }

                width = c.Size;
                position = new Point(position.X + c.Location.X, position.Y + c.Location.Y);
                c = c.Parent;
            }

            v.Location = new Point(position.X + (sc.Width - v.Width) / 2, position.Y - v.Height - 3);

            return v.ShowDialog() == System.Windows.Forms.DialogResult.OK;
        }
    }
}
